<template>
  <div class="register">
    <!-- ref="registerForm"
      :model="registerForm"
      :rules="registerRules" -->
    <el-form
      ref="form" :model="form" :rules="rules" label-width="120px"  class="register-form"
      width="800"
    >
      <h3 class="title">培训考试系统</h3>
      <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="ksName">
              <el-input v-model="form.ksName" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="ksSex">
              <el-select
                v-model="form.ksSex"
                placeholder="请选择性别"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in ksSexOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="民族" prop="nation">
              <el-select
                v-model="form.nation"
                placeholder="请选择民族"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in nationOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生年月" prop="birthDate" >
              <el-date-picker
                clearable
                size="small"
                v-model="form.birthDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择出生年月"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
                    </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="籍贯" prop="nativePlace">
              <el-input v-model="form.nativePlace" placeholder="请输入籍贯" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生地" prop="birthPlace">
              <el-input v-model="form.birthPlace" placeholder="请输入出生地" />
            </el-form-item>
          </el-col>
                    </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="政治面貌" prop="politicalStatus">
              <el-input
                v-model="form.politicalStatus"
                placeholder="请输入政治面貌"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入党时间" prop="joinDate">
              <!-- <el-input v-model="form.joinDate" placeholder="请输入入党时间" /> -->
              <el-date-picker
                clearable
                size="small"
                v-model="form.joinDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择入党时间"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
                    </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="现户籍地" prop="currentPlace">
              <el-input
                v-model="form.currentPlace"
                placeholder="请输入现户籍地"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="婚姻状况" prop="maritalStatus">
              <el-select
                v-model="form.maritalStatus"
                placeholder="请选择婚姻状况"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in maritalStatusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
                    </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="身份证号码" prop="cardNumber">
              <el-input
                v-model="form.cardNumber"
                placeholder="请输入身份证号码"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phonenumber">
              <el-input
                v-model="form.phonenumber"
                placeholder="请输入联系电话"
              />
            </el-form-item>
          </el-col>
                    </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="外语水平" prop="foreignLanguage">
              <el-input
                v-model="form.foreignLanguage"
                placeholder="请输入外语水平"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计算机水平" prop="computerProficiency">
              <el-input
                v-model="form.computerProficiency"
                placeholder="请输入计算机水平"
              />
            </el-form-item>
          </el-col>
                    </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="电子邮箱" prop="ksEmail">
              <el-input v-model="form.ksEmail" placeholder="请输入电子邮箱" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通讯地址" prop="mailAddress">
              <el-input
                v-model="form.mailAddress"
                placeholder="请输入通讯地址"
              />
            </el-form-item>
          </el-col>
                    </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="参加工作时间" prop="workDate">
              <el-date-picker
                clearable
                size="small"
                v-model="form.workDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择参加工作时间"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="应聘-专业方向" prop="ksSpecialty">
              <el-select
                v-model="form.ksSpecialty"
                placeholder="请选择应聘-专业方向"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in ksSpecialtyOptions"
                  :key="dict.id"
                  :label="dict.label"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="学历" prop="qualification">
              <el-select
                v-model="form.qualification"
                placeholder="请选择学历"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in qualificationOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业院校" prop="bySchool">
              <el-input v-model="form.bySchool" placeholder="请输入毕业院校" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="密码" prop="password">
              <el-input v-model="form.password" placeholder="请输入密码" />
            </el-form-item>
          </el-col>
        </el-row>
      <!-- <el-form-item prop="username">
        <el-input
          v-model="registerForm.username"
          type="text"
          auto-complete="off"
          placeholder="账号"
        >
          <svg-icon
            slot="prefix"
            icon-class="user"
            class="el-input__icon input-icon"
          />
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="registerForm.password"
          type="password"
          auto-complete="off"
          placeholder="密码"
          @keyup.enter.native="handleRegister"
        >
          <svg-icon
            slot="prefix"
            icon-class="password"
            class="el-input__icon input-icon"
          />
        </el-input>
      </el-form-item>
      <el-form-item prop="confirmPassword">
        <el-input
          v-model="registerForm.confirmPassword"
          type="password"
          auto-complete="off"
          placeholder="确认密码"
          @keyup.enter.native="handleRegister"
        >
          <svg-icon
            slot="prefix"
            icon-class="password"
            class="el-input__icon input-icon"
          />
        </el-input>
      </el-form-item>
      <el-form-item prop="code" v-if="captchaOnOff">
        <el-input
          v-model="registerForm.code"
          auto-complete="off"
          placeholder="验证码"
          style="width: 63%"
          @keyup.enter.native="handleRegister"
        >
          <svg-icon
            slot="prefix"
            icon-class="validCode"
            class="el-input__icon input-icon"
          />
        </el-input>
        <div class="register-code">
          <img :src="codeUrl" @click="getCode" class="register-code-img" />
        </div>
      </el-form-item> -->
      <el-form-item style="width: 100%">
        <el-button
          :loading="loading"
          size="medium"
          type="primary"
          style="width: 100%"
          @click.native.prevent="handleRegister"
        >
          <span v-if="!loading">注 册</span>
          <span v-else>注 册 中...</span>
        </el-button>
        <div style="float: right">
          <router-link class="link-type" :to="'/login'"
            >使用已有账户登录</router-link
          >
        </div>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <!-- <div class="el-register-footer">
      <span>©2022 . All Rights Reserved </span>
    </div> -->
  </div>
</template>

<script>
import { listExamtreeselect, register } from '@/api/login'
import {
  addKsUser,
} from "@/api/whpx/ksUser";
export default {
  name: 'Register',
  data() {
    return {
       // 性别字典
      ksSexOptions: [],
      // 民族字典
      nationOptions: [],
      // 出生年月时间范围
      daterangeBirthDate: [],
      // 婚姻状况字典
      maritalStatusOptions: [],
      // 应聘-专业方向字典
      ksSpecialtyOptions: [],
      // 学历字典
      qualificationOptions: [],
      form: {},
      rules: {
        ksName: [{ required: true, message: "姓名不能为空", trigger: "blur" }],

        ksSex: [{ required: true, message: "性别不能为空", trigger: "change" }],

        nation: [
          { required: true, message: "民族不能为空", trigger: "change" },
        ],

        birthDate: [
          { required: true, message: "出生年月不能为空", trigger: "blur" },
        ],

        nativePlace: [
          { required: true, message: "籍贯不能为空", trigger: "blur" },
        ],

        birthPlace: [
          { required: true, message: "出生地不能为空", trigger: "blur" },
        ],

        politicalStatus: [
          { required: true, message: "政治面貌不能为空", trigger: "blur" },
        ],

        currentPlace: [
          { required: true, message: "现户籍地不能为空", trigger: "blur" },
        ],

        cardNumber: [
          { required: true, message: "身份证号码不能为空", trigger: "blur" },
        ],

        phonenumber: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
        ],
      },
      loading: false,
      captchaOnOff: true
    }
  },
  created() {
    this.getlistExamtreeselect();
   this.getDicts("sys_user_sex").then((response) => {
      this.ksSexOptions = response.data;
    });
    this.getDicts("nation_type").then((response) => {
      this.nationOptions = response.data;
    });
    this.getDicts("marital_type").then((response) => {
      this.maritalStatusOptions = response.data;
    });
    // this.getDicts("specialty_type").then((response) => {
    //   this.ksSpecialtyOptions = response.data;
    // });
    this.getDicts("qualification_key").then((response) => {
      this.qualificationOptions = response.data;
    });
    this.getDicts("sys_common_status").then((response) => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    getlistExamtreeselect() { 
      listExamtreeselect().then((res) => { 
        this.ksSpecialtyOptions = res.data
      })
    },
    handleRegister() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          addKsUser(this.form)
            .then(res => {
              const username = this.form.ksName
              this.$alert(
                "<font color='red'>恭喜你，您的账号 " +
                  username +
                  ' 注册成功！</font>',
                '系统提示',
                {
                  dangerouslyUseHTMLString: true
                }
              )
                .then(() => {
                  this.$router.push('/login')
                })
                .catch(() => {})
            })
            .catch(() => {
              this.loading = false
            
            })
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.register {
  display: flex;
  justify-content: right;
  padding-right: 30px;
  box-sizing: border-box;
  align-items: center;
  height: 100%;
  background-image: url('../assets/images/login-background.png');
  background-size: 100% 100%;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #000000;
  font-size: 22px;
  letter-spacing: 1px;
}

.register-form {
  border-radius: 6px;
  background: #ffffff;
  width: 800px;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.register-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.register-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-register-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.register-code-img {
  height: 38px;
}
</style>
